package controllers

import (
	"github.com/xgggh/test/api/entity"
	"github.com/xgggh/test/api/models"
	"encoding/json"
	"github.com/xgggh/test/api/demo"
)



// 测试任务类
type TaskController struct {
	BaseController
}

// @Title 创建API测试任务
// @Description 创建API测试任务
// @Param	body		body 	entity.Task	true		"The object content"
// @Success 200 {string} entity.Task.Id
// @Failure 403 body is empty
// @router / [post]
func (c *TaskController) Post() {
	var task entity.Task = entity.Task{
		Title:"登陆API",
	}
	json.Unmarshal(c.Ctx.Input.RequestBody,&task)
	taskId ,err:= models.AddOne(demo.GetTaskDemo())
	if err!=nil {
		c.Data["json"] = "server error"
		c.ServeFormatted()
		return
	}
		//Rsp()
	c.Data["json"] = map[string]int64{"taskId": taskId}
	c.ServeFormatted()
}

// @Title 查询API测试任务
// @Description 通过taskId查询API测试任务
// @Param	taskId		path 	string	true   "查询任务ID"
// @Success 200 {object} entity.Task
// @Failure 403 :taskId is empty
// @router /:taskId [get]
func (c *TaskController) Get() {
	/*objectId := c.Ctx.Input.Param(":taskId")
	if objectId != "" {
		ob, err := models.GetOne(objectId)
		if err != nil {
			c.Data["json"] = err.Error()
		} else {
			c.Data["json"] = ob
		}
	}*/
	c.ServeJSON()
}

// @Title 查询API测试任务
// @Description 查询API测试任务列表
// @Success 200 {object} entity.Task
// @Failure 403 :taskId is empty
// @router / [get]
func (c *TaskController) GetAll() {
	/*obs := models.GetAll()
	c.Data["json"] = obs*/
	c.ServeJSON()
}

// @Title 修改API测试任务
// @Description 修改API测试任务属性
// @Param	taskId		path 	string	true		"The objectid you want to update"
// @Param	body		body 	entity.Task	true		"The body"
// @Success 200 {object} entity.Task
// @Failure 403 :taskId is empty
// @router /:taskId [put]
func (c *TaskController) Put() {
	/*taskId := c.Ctx.Input.Param(":taskId")
	var ob entity.Task
	json.Unmarshal(c.Ctx.Input.RequestBody, &ob)

	err := models.Update(taskId, ob.ProductId)
	if err != nil {
		c.Data["json"] = err.Error()
	} else {
		c.Data["json"] = "update success!"
	}*/
	c.ServeJSON()
}

// @Title 删除API测试任务
// @Description 删除API测试任务 如果有依赖条件，必须先解除依赖
// @Param	taskId		path 	string	true		"The taskId you want to delete"
// @Success 200 {string} delete success!
// @Failure 403 taskId is empty
// @router /:taskId [delete]
func (c *TaskController) Delete() {
	/*taskId := c.Ctx.Input.Param(":taskId")
	models.Delete(taskId)*/
	c.Data["json"] = "delete success!"
	c.ServeJSON()
}

